MyModules.define('layout',[],function(){
	function render(){
		var id = this.datas.id;
		var content = this.inputTemplate(this.datas.id, this.datas.value);
		var str = widgetHtml.modal(this.datas.id, content, this.datas.value);
		return str;
	}
	function getHtml () {
		var str = '<div class="wrap-widget LdgFormItemGird" data-id="'+this.datas.id+'"  data-original-title="'+this.datas.name+'" data-toggle="tooltip">';
		str += '</div>';
		
		return str;
	}
	class Child extends ContainWidgetObject {
	    constructor() {
	        super(); // 调用父类构造函数
	        // 子类可以添加自己的属性或方法
	        this.name = '佈局';
		    this.datas = {
				//控件属性
				name: '佈局', //控件名称
				type: 'layoutWidget',
				target:'container',
				value:[{
					col:12
				}]
				,
				childs: []
			};
		    this.init = function(){
				if(empty(this.datas.childs)){
					this.datas.childs = new Array();
					this.datas.childs.push(dragObj.toControl('container'));
				}
			};
			this.render = render;
			this.getHtml = getHtml;
			this.inputTemplate = function(id, value){
				var num = this.datas.value['content'] ? this.datas.value['content'] : this.datas.childs[0];
	            var str = widgetHtml.dropDownList('content', num, '列表数', {'1':'col-12','2':'col-6','3':'col-4','4':'col-3','5':'col-25','6':'col-2'});
	            return str;
	        };
	        this.saveData = function(){
	        	var values = $("#myModal form").serializeArray();
				this.datas.value = arrayToObject(values);
				this.datas.childs = [Number(this.datas.value['content'])];
				var node = dragObj.node.getElementById(this.datas['id']);
				var now_length = node.childNodes.length;
				var new_node = dragObj.node;
				for(var x =0; x<this.datas.childs[0];x++){
					if(empty(node.childNodes[x])){
						var container = dragObj.toControl('container');
						var indexs = {parent:this.datas['id'], index:x};
						dragObj.renderNode(container, indexs);
						new_node = dragObj.addToNode(new_node, indexs, container, 0);
					}
				}
				if(now_length > this.datas.childs[0]){
					for (var i = now_length - 1 ; i >=this.datas.childs[0] ; i--) {
						dragObj.removeDo(node.childNodes[i].getAttribute('id'));
					}
				}
	        }
	        this.setData = function(type){
	        	var cols = []
				var num = 0
				switch(type){
					case 20:
						cols = [{col:6},{col:6}];
						num = 2
						break;
					case 30:
						cols = [{col:4},{col:4},{col:4}];
						num = 3
						break;
					case 40:
						cols = [{col:3},{col:3},{col:3},{col:3}];
						num = 4
						break;
					case 21:
						cols = [{col:4},{col:8}];
						num = 2
						break;
					case 22:
						cols = [{col:8},{col:4}];
						num = 2
						break;
					case 31:
						cols = [{col:3},{col:3},{col:6}];
						num = 3
						break;
					case 32:
						cols = [{col:6},{col:3},{col:3}];
						num = 3
						break;
					case 33:
						cols = [{col:3},{col:6},{col:3}];
						num = 3
						break;
					case 34:
						cols = [{col:2},{col:8},{col:2}];
						num = 3
						break;
					case 50:
						cols = [{col:25},{col:25},{col:25},{col:25},{col:25}];
						num = 5
						break;
					case 60:
						cols = [{col:2},{col:2},{col:2},{col:2},{col:2},{col:2}];
						num = 6
						break;
					default:
						cols = [{col:12}]
						break;
				}
				
				this.datas.value['cols'] = cols;
				this.datas.value['content'] = num;
				this.datas.childs = [num];
	        }
	    }
	}
	return new Child();
});